<?php
/**
 * 兑换奖品 列表
 */

namespace app\api\model;


use app\common\model\Model;

class ExchangePrize extends Model
{
    const TABLE_NAME = 'exchange_prize_list';
    const CACHE_EXPIRE_LEVEL = self::CACHE_EXPIRE_LEVEL_1;
    const PRIZE_IMAGE_PATH='prize';
    protected $name = self::TABLE_NAME;

    public static function getPrizeList()
    {
        return self::commonQuery(self::TABLE_NAME)
               ->select();
    }
    public static function getPrizeInfo($prize_id)
    {
        return self::commonQuery(self::TABLE_NAME,self::CACHE_EXPIRE_LEVEL)
              ->where(['prize_id'=>$prize_id])
              ->find();
    }
    public static function handlePrizeInfo($info,$user_id)
    {
        if(empty($info))
        {
            return [];
        }
        $info['user_is_exchange']=ExchangeRecord::isUserExchangePrize($user_id,$info['prize_id']);
        $info['prize_img']=get_image_url(self::PRIZE_IMAGE_PATH,$info['prize_img']);
        return $info;
    }
    public static function handlePrizeList($list,$user_id)
    {
        $res=[];
        if(empty($list))
        {
            return $res;
        }
        foreach ($list as $key=>$val)
        {
            $res[$key]= self::handlePrizeInfo($val,$user_id);
        }
        return $res;
    }
}